using System;
using System.Collections.Generic;

namespace MonoNZB.NNTP 
{
	public class Server
	{
		public enum Field
		{
			HOSTNAME,
			PORT,
			CONNECTIONS,
			SSL,
			USERNAME,
			PASSWORD
		}
		
		public string Hostname { get; set; }
		public int Port { get; set; }
		public List<Connection> Connections { get; set; }
		public bool SSL;
		public string Username { get; set; }
		public string Password { get; set; }
		public bool Connected
		{
			get
			{
				foreach (Connection connection in Connections)
				{
					if (!connection.Connected)
					{
						return false;	
					}
				}
				return true;
			}
		}
		
		public Server(string Hostname, int Port, int Connections)
		{
			this.Hostname = Hostname;
			this.Port = Port;
			this.Connections = new List<Connection>();
			for (int i = 0; i < Connections; i++)
			{
				Connection connection = new Connection(this);
				this.Connections.Add(connection);
			}
		}
		
		public Server(string Hostname, int Port, int Connections, bool SSL)
			: this(Hostname, Port, Connections)
		{
			this.SSL = SSL;
		}
		
		public Server(string Hostname, int Port, int Connections, string Username, string Password)
			: this(Hostname, Port, Connections)
		{
			this.Username = Username;
			this.Password = Password;
		}
		
		public Server(string Hostname, int Port, int Connections, string Username, string Password, bool SSL)
			: this(Hostname, Port, Connections, Username, Password)
		{
			this.SSL = SSL;	
		}
		
		public void Connect()
		{
			foreach (Connection connection in Connections)
			{
				connection.Connect();	
			}
		}
		
		public void Disconnect()
		{
			if (!Connected)
			{
				return;
			}
			
			foreach (Connection connection in Connections)
			{
				connection.Disconnect();	
			}
		}
	}
}
